package com.whiteape.book.ui.adapter;

import android.graphics.Color;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.whiteape.book.R;
import com.whiteape.book.model.dto.SiteSourceBean;
import com.whiteape.book.model.type.MediaType;
import com.whiteape.book.model.type.RVLayoutType;

import java.util.ArrayList;
import java.util.List;

public class HomepageChooseSourceAdapter extends BaseQuickAdapter<SiteSourceBean, BaseViewHolder> {

    private SiteSourceBean curSiteSourceBean;

    public HomepageChooseSourceAdapter(int layoutResId, @Nullable List<SiteSourceBean> data) {
        super(layoutResId, data);
    }

    public SiteSourceBean getCurSiteSourceBean() {
        return curSiteSourceBean;
    }

    public void setCurSiteSourceBean(SiteSourceBean curSiteSourceBean) {
        this.curSiteSourceBean = curSiteSourceBean;
    }

    @Override
    protected void convert(BaseViewHolder helper, SiteSourceBean item) {

        if(curSiteSourceBean != null && curSiteSourceBean.getSiteHostUrl().equals(item.getSiteHostUrl())) {
//            helper.setBackgroundColor(R.id.rl_homepage_choose_source, Color.parseColor("#90C5F0"));
            helper.setBackgroundRes(R.id.rl_homepage_choose_source, R.drawable.selected_source_border);
        }else {

            helper.setBackgroundColor(R.id.rl_homepage_choose_source, Color.parseColor("#ffffff"));
        }

        helper.setText(R.id.tv_site_name, item.getSiteName());
        Glide.with(mContext)
                .load(item.getSiteIconUrl())
                .placeholder(R.mipmap.no_cover_landscape)
                .fitCenter()
                .into((ImageView) helper.getView(R.id.iv_site_cover));

    }

}
